import React,{useState} from 'react'
import store from '../store'
import {incrementAction} from '../store/actions/counterAction'
export default function Counter() {
  const [aa,setAa]=useState(0)
  console.log('store',store.getState());
  const increment=()=>{
    store.dispatch(incrementAction)
  }
  //专门用于监听仓库中变化的数据，一旦数据变化了store的subscribe函数就会调用
  store.subscribe(()=>{
    console.log('store中数据',store.getState());
    //下面这个代码主要是为了让组件重新渲染的
    setAa({})
  })
  
  return (
    <div>
        <h2>{store.getState()}</h2>
        <button onClick={increment}>+</button>
    </div> 
  )
}
